import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true
  },

  {
    path: "/",
    component: Layout,
    redirect: "/home",
    children: [
      {
        path: "home",
        name: "Home",
        component: () => import("@/views/home/index"),
        meta: { title: "首页", icon: "el-icon-s-home" }
      }
    ]
  },

  {
    path: "/system",
    component: Layout,
    redirect: "/system/user",
    name: "systemManager",
    meta: { title: "系统管理", icon: "el-icon-setting" },
    children: [
      {
        path: "user",
        name: "User",
        component: () => import("@/views/userManager/user"),
        meta: { title: "用户管理", icon: "el-icon-user" }
      },
      {
        path: "wxuser",
        name: "WxUser",
        component: () => import("@/views/userManager/wxuser"),
        meta: { title: "微信用户管理", icon: "el-icon-user" }
      },
      {
        path: "role",
        name: "Role",
        component: () => import("@/views/userManager/role"),
        meta: { title: "角色管理", icon: "el-icon-user-solid" }
      }
    ]
  },

  {
    path: "/book",
    component: Layout,
    redirect: "/book/list",
    name: "Book",
    meta: {
      title: "图书管理",
      icon: "el-icon-notebook-1"
    },
    children: [
      {
        path: "list",
        component: () => import("@/views/book/list/index"), // Parent router-view
        name: "List",
        meta: { title: "书籍管理", icon: "el-icon-notebook-2" }
      },
      {
        path: "author",
        component: () => import("@/views/book/author/index"),
        name: "Author",
        meta: { title: "作者管理", icon: "el-icon-s-custom" }
      },
      {
        path: "category",
        component: () => import("@/views/book/category/index"),
        name: "Category",
        meta: { title: "书籍分类管理", icon: "el-icon-c-scale-to-original" }
      }
    ]
  },

  {
    path: "external-link",
    component: Layout,
    children: [
      {
        path: "https://www.baidu.com",
        meta: { title: "链接", icon: "link" }
      }
    ]
  },

  { path: "*", redirect: "/404", hidden: true }
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  });

const router = createRouter();


export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
